package com.xms.datacore.service;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xms.core.exception.XmsException;
import com.xms.datacore.TransactionUtil;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.List;

/**
 * <p>
 * UpdaterService
 * </p>
 *
 * @author migo
 * @since 2021/9/2
 */
public class UpdaterService<T> extends ServiceImpl<BaseMapper<T>, T> implements IUpdaterService<T> {

    @Override
    public IService<T> getService() {
        return this;
    }

    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean update(T entity) throws XmsException, SQLException {
        return super.updateById(entity);
    }

    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean updateMany(List<T> entityList) throws XmsException, SQLException {
        return super.saveBatch(entityList);
    }

    @Override
    public void rollBack(){
        TransactionUtil.rollBack();
    }
}
